<!-- templates/status.html -->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>系统状态 - 花艺AI测试应用</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body { padding-top: 2rem; }
        .header { margin-bottom: 2rem; }
        .status-container { max-width: 800px; margin: 0 auto; }
    </style>
</head>
<body>
    <div class="container">
        <div class="header text-center">
            <h1>花艺AI测试应用</h1>
            <p class="lead">系统状态</p>
            <nav class="nav justify-content-center">
                <a class="nav-link" href="/">首页</a>
                <a class="nav-link" href="/upload">上传知识</a>
                <a class="nav-link" href="/image">生成图像</a>
                <a class="nav-link" href="/status">系统状态</a>
            </nav>
        </div>

        <div class="status-container">
            <div class="card mb-3">
                <div class="card-header bg-info text-white">
                    <h5 class="mb-0">知识库状态</h5>
                </div>
                <div class="card-body">
                    <p><strong>文档数量:</strong> {{ status.knowledge_base.document_count }}</p>
                    <p><strong>最后更新时间:</strong> {{ status.knowledge_base.last_updated }}</p>
                </div>
            </div>

            <div class="card mb-3">
                <div class="card-header bg-info text-white">
                    <h5 class="mb-0">本地模型状态</h5>
                </div>
                <div class="card-body">
                    <p><strong>模型可用:</strong> {% if status.local_model.available %}是{% else %}否{% endif %}</p>
                    <p><strong>模型路径:</strong> {{ status.local_model.model_path }}</p>
                    <button id="trainButton" class="btn btn-primary">训练本地模型</button>
                    <div id="trainResult" class="mt-3 d-none">
                        <div class="alert alert-info">
                            <span id="trainMessage"></span>
                        </div>
                    </div>
                </div>
            </div>

            <div class="card mb-3">
                <div class="card-header bg-info text-white">
                    <h5 class="mb-0">API状态</h5>
                </div>
                <div class="card-body">
                    <p><strong>API状态:</strong> {{ status.api_status }}</p>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        document.getElementById('trainButton').addEventListener('click', function() {
            const resultDiv = document.getElementById('trainResult');
            const resultMessage = document.getElementById('trainMessage');

            fetch('/train')
            .then(response => response.json())
            .then(data => {
                resultDiv.classList.remove('d-none');
                resultMessage.textContent = data.message || JSON.stringify(data);
            })
            .catch(error => {
                resultDiv.classList.remove('d-none');
                resultMessage.textContent = '训练请求失败: ' + error;
            });
        });
    </script>
</body>
</html>
